//
//  HotView.swift
//  shop
//
//  Created by chen on 2025/5/17.
//

import SwiftUI

struct HotView: View {
    
    @StateObject private var vm: HotViewModel = HotViewModel.shared
    @EnvironmentObject private var router: Router
    
    var body: some View {
        ZStack{
            Color.detailBg
                .ignoresSafeArea()
            
            VStack(spacing: 0) {
                CommonHeader(title: "热销爆款")
                
                ScrollView(showsIndicators: false) {
                    WaterfallGrid(items: vm.goodsResp.list) { item in
                        Button {
                            router.to(.detailView(id: item.id))
                        } label: {
                            ProductCard(item: item)
                        }
                        .buttonStyle(PlainButtonStyle())
                    }
                    .padding(.vertical, 10)
                    .onAppear{
                        vm.getGoodsList()
                    }
                }
            }
        }
        .navigationBarBackButtonHidden(true)
    }
}

#Preview {
    HotView()
        .environmentObject(Router.shared)
}
